package main

import (
	"log"
	"weboffice-go-sdk/examples/internal/demo"
	"weboffice-go-sdk/weboffice"
)

type TestProvider struct {
	demo *demo.Provider
}

func (t *TestProvider) GetFile(ctx weboffice.Context, fileID string) (*weboffice.GetFileReply, error) {
	if ctx.Token() != "token123" {
		return nil, weboffice.NewCustomError("custom error message")
	}
	return t.demo.GetFile(ctx, fileID)
}

func (t *TestProvider) GetFileDownload(ctx weboffice.Context, fileID string) (*weboffice.GetFileDownloadReply, error) {
	if ctx.Token() != "token123" {
		return nil, weboffice.NewCustomError("custom error message")
	}
	return t.demo.GetFileDownload(ctx, fileID)
}

func (t *TestProvider) GetFilePermission(ctx weboffice.Context, fileID string) (*weboffice.GetFilePermissionReply, error) {
	if ctx.Token() != "token123" {
		return nil, weboffice.NewCustomError("custom error message")
	}
	return t.demo.GetFilePermission(ctx, fileID)
}

func main() {
	provider := &TestProvider{
		demo: demo.NewProvider(),
	}

	server := weboffice.NewServer(weboffice.Config{
		BaseProvider: provider,
		Logger:       weboffice.DefaultLogger(),
		Prefix:       "/weboffice-go-sdk/",
	})
	server.Router().GET("/download", provider.demo.DownloadFile)

	if err := server.Run(":8080"); err != nil {
		log.Fatal(err)
	}
}
